<template>
    <div class="" id="ProjectSummary">
        <div>
            <h1 class="text-success">项目汇总</h1>
        </div>
        <hr>

        <div class="row">
            <Label :label_info="code_label_info.patch" :label_data="code_label_data.g_number__count"></Label>
            <Label :label_info="code_label_info.insert" :label_data="code_label_data.g_lines_insert__sum"></Label>
            <Label :label_info="code_label_info.delete" :label_data="code_label_data.g_lines_delete__sum"></Label>
            <Label :label_info="code_label_info.inline_c" :label_data="code_label_data.g_inline_comments__sum"></Label>
            <Label :label_info="code_label_info.patch_without_inline_c" :label_data="code_label_data.no_comment_patch"></Label>
            <Label :label_info="code_label_info.defect_concentration" :label_data="code_label_data.g_defect_review"></Label>
            <Label :label_info="code_label_info.defect_effective_rate" :label_data="code_label_data.g_effective_radio"></Label>
        </div>

        <div class="row">
            <DataTable :table_id="code_tableinfo_summary.id" :table_title="code_tableinfo_summary.title" :columns="code_tableinfo_summary.columns" 
                :table_data='code_tableinfo_summary.table_data' :columns_key="code_tableinfo_summary.columns_key" :column_id="code_tableinfo_summary.column_id">     
            </DataTable>
        </div>

    </div>
</template>
<script>
import Label from '@/components/qa/Label.vue'
import DataTable from '@/components/qa/DataTable'
export default {
    name: 'ProjectSummary',
    components: {
        Label,
        DataTable,
    },
    data() {
        return {
            code_label_info: {
                patch: {
                    label_hname: 'Patch',
                    label_sname: 'Total Patches',
                    label_unit: '(个)',
                    label_class: 'success',
                },
                insert: {
                    label_hname: '代码新增',
                    label_sname: 'Total Lines',
                    label_unit: '(行)',
                    label_class: 'success',
                },
                delete: {
                    label_hname: '代码删除',
                    label_sname: 'Total Lines',
                    label_unit: '(行)',
                    label_class: 'success',
                },
                inline_c: {
                    label_hname: '行内注释',
                    label_sname: 'Total',
                    label_unit: '(个)',
                    label_class: 'success',
                },
                patch_without_inline_c: {
                    label_hname: '无行内注释Patch',
                    label_sname: 'Total Patches',
                    label_unit: '(个)',
                    label_class: 'danger',
                },
                defect_concentration: {
                    label_hname: '评审缺陷密度',
                    label_sname: 'Total',
                    label_unit: '(个/Kloc)',
                    label_class: 'warning',
                },
                defect_effective_rate: {
                    label_hname: '评审有效比率',
                    label_sname: 'Total',
                    label_unit: '(%)',
                    label_class: 'warning',
                }
            },
            code_label_data: {
            },
            code_tableinfo_summary: {
                id: 'table_summart',
                title: '分支数据汇总',
                columns: ['分支名称','Patch(个)','代码新增(行)','代码删除(行)','行内注释(个)','评审缺陷密度(个/Kloc)',
                    '评审有效比率(%)','操作'],
                table_data: [],
                columns_key: ['g_branch','g_number__count','g_lines_insert__sum','g_lines_delete__sum',
                'g_inline_comments__sum','g_defect_review','g_effective_radio'],
                column_id: 7,
            },
        }
    },
    methods: {
        getData: function() {
            this.getProjectGerritSumLabel('Gundam');
            this.getProjectGerritSumTab('Gundam');
            // this.getCodeSummary('Gundam');
        },
        getProjectGerritSumLabel: function(project) {
            this.$axios.get('/api/qa/projectgerritsumlabel/?project='+project)
                .then((response) => {
                    if (response.status == 200) {
                        // eslint-disable-next-line
                        // console.log(response.data.summary);
                        this.code_label_data = response.data.sum;
                    }
                })
                .catch(function(err) {
                    // eslint-disable-next-line
                    console.log(err);
                });
        },
        getProjectGerritSumTab: function(project) {
            this.$axios.get('/api/qa/projectgerritsumtab/?project='+project)
                .then((response) => {
                    if (response.status == 200) {
                        // eslint-disable-next-line
                        // console.log(response.data.summary);
                        this.code_tableinfo_summary.table_data = response.data.sum;
                    }
                })
                .catch(function(err) {
                    // eslint-disable-next-line
                    console.log(err);
                });
        }
    },
    mounted: function() {
        this.getData();
    }
}
</script>
